
#include "private_implementations/JsonNode.h"

namespace simframework
{
	namespace json
	{

		JsonObjectNode::JsonObjectNode(const std::wstring& value):m_key(value)
		{
		}

		void JsonObjectNode::addNode(IJsonNode* value)
		{
			m_childList[value->getKey()] = value;
		}
		const std::wstring& JsonObjectNode::getKey() const
		{
			return m_key;
		}

		const JsonObjectNode* JsonObjectNode::getInternalValue() const
		{
			return this;
		}

		JsonObjectNode::~JsonObjectNode()
		{
			for (stdext::hash_map<std::wstring, IJsonNode*>::iterator itr = m_childList.begin(), e_itr = m_childList.end(); itr != e_itr; ++itr)
			{
				delete itr->second;
			}
		}		
		/*********/

		JsonArrayNode::JsonArrayNode( const std::wstring& value ):m_key(value)
		{

		}
		void JsonArrayNode::addNode(IJsonNode* value)
		{
			m_childList.push_back(value);
		}
		const std::wstring& JsonArrayNode::getKey() const
		{
			return m_key;
		}

		const JsonArrayNode* JsonArrayNode::getInternalValue() const
		{
			return this;
		}

		JsonArrayNode::~JsonArrayNode()
		{
			for (std::vector<IJsonNode*>::iterator itr = m_childList.begin(), e_itr = m_childList.end(); itr != e_itr; ++itr)
			{
				delete *itr;
			}
		}

		size_t JsonArrayNode::size() const
		{
			return m_childList.size();
		}
		/***************/


		JsonStringNode::JsonStringNode(const std::wstring& key, const std::wstring& value):m_key(key), m_value(value)
		{
		}

		const std::wstring& JsonStringNode::getKey() const
		{
			return m_key;
		}

		const std::wstring& JsonStringNode::getInternalValue() const 
		{
			return m_value;
		}
		/************/


		JsonBoolNode::JsonBoolNode(const std::wstring& key, bool value):m_key(key), m_value(value)
		{
		}

		const std::wstring& JsonBoolNode::getKey() const
		{
			return m_key;
		}

		bool JsonBoolNode::getInternalValue() const 
		{
			return m_value;
		}

		/**********/


		JsonDoubleNode::JsonDoubleNode(const std::wstring& key, double value):m_key(key), m_value(value)
		{
		}

		const std::wstring& JsonDoubleNode::getKey() const
		{
			return m_key;
		}

		double JsonDoubleNode::getInternalValue() const 
		{
			return m_value;
		}

		/*************/


		JsonNullNode::JsonNullNode(const std::wstring& value):m_key(value)
		{
		}

		const std::wstring& JsonNullNode::getKey() const
		{
			return m_key;
		}

		NullType JsonNullNode::getInternalValue() const 
		{
			return null;
		}
	}
}